﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL_V1.App_Code.DBBroker;
using EntityObjects;
namespace BAL.Controller
{
    public class ViewCatalogueForClerkContol
    {
        CatalogueDBBroker cDB;
        public ViewCatalogueForClerkContol() {
            cDB = CatalogueDBBroker.getCatalogueDBBroker();
        }


        public List<Category> getCategory()
        {
            return cDB.selectAllCategory();
            
        }
        public List<String> getBin()
        {
            int a = 0;
            List<String> b = new List<String>();
            List<Catalogue> temp = getCatalogue();      
           
            foreach(Catalogue c in temp)
            {
                if (!b.Contains(c.BinId)) b.Add(c.BinId);
            }
            return b;
          }

        public List<Catalogue> getCatalogue()
        {
            return cDB.getCatalogueForClerk();
        }

        public List<Catalogue> searchByCategory(int p)
        {
            return cDB.selectCatalogueByCategoryId(p);
         
        }
                
        public List<Catalogue> searchByBinId(String p)
        {
            return cDB.getCatalogueByBinId(p);
        }



        public List<Catalogue> searchWithoutBin(int id, string desc)
        {
            if (id != 0)
            {
                if (desc != "")
                {
                    return cDB.getCatalogueByDescAndCategory(desc, id);
                }
                else
                    return cDB.selectCatalogueByCategoryId(id);
            }
            else if (id == 0)
            {
                if (desc != "") return cDB.getCatalogueByDesc(desc);
                else return cDB.selectAllCatalogue() ;
            }
            else
                return null;
            
            
        }

        public List<Catalogue> searchWithBin(int id, string desc, string bin)
        {
            if (id != 0)
            {
                if (desc != "")
                {
                    return cDB.getCatalogueByBinAndCategoryAndDesc(bin, id, desc);
                }
                else
                    return cDB.getCatalogueByBinAndCategory(bin, id);
            }
            else if (id == 0)
            {
                if (desc != "")
                {
                    return cDB.getCatalogueByBinAndDesc(bin, desc);
                }
                else
                    return cDB.getCatalogueByBinId(bin);
            }
            else return null;
        }

            }
}
